<%@ page import="databeans.*"%>
<%@ page import="helper.*"%>
<jsp:include page="../common/header.jsp" />
<%@ page import="java.util.ArrayList" %>

<script type="text/javascript">
	$(document).ready(function() { 

        $("#popup").dialog({ bgiframe: true, autoOpen:false, modal: true, closeOnEscape: true, draggable:false, width:700, height:500, position: 'top', buttons: { "Close": function() { $(this).dialog('close'); } } });
		
		$('a#sell-funds').click(function(e) { 
			var id = $(this).attr('href');
			var fund_id = id.substring(1,id.length);
			//alert(customer_id);
			e.preventDefault(); 
			$('#popup').dialog('open'); 
			$('#txtFundID').attr('value',fund_id);
		});
		$('#sell-fund').click(function(e) {
        	var queryString = $('.sell-form').formSerialize();
        	//alert(queryString);
			e.preventDefault(); 
			$('#popup').html('<img src=\"view/img/mozilla_blu.gif\"></img> Fetching Data... Please wait');
			$.post(
				       
				    "customerSellFund.do", //Ajax file
				    queryString,
				    //function that is called when server returns a value.
					    function(html){
				    		//$('.create-cust-result').slideUp();
					        $('#popup').html(html); // Populate Data through this line
							//alert($('.create-cust-result').height());
							//var ht = $('.create-customer').height();
							//ht += $('.create-cust-result').height();
							//$div.css({ height : ht });
				    	},
				    	"html"
				    );
		}); 
		$('#colorize_1').colorize({ hoverColor:'none', ignoreHeaders :true, hiliteColor :'none' });
		
	});
</script>

<title>Carnegie Financial Services - View Funds</title>
</head>

<body>
	<div id="container">
    	<div id="header">
        	<h2>Carnegie Financial Services</h2>
    		<jsp:include page="../common/top-menu.jsp" />
      </div>
        <div id="wrapper">
            <div id="content">
				<div id="infowrap">
					<jsp:include page="../common/messages.jsp"/>
					<!-- 
					<div id="infobox">
						<h3>Sales for This Month</h3>
						<p>Some Graph Here</p>            
					</div>
					 -->
					<div id="box">
						<h3>Fund Summary</h3> 
						<table id="colorize_1">
							<thead>
								<tr>
									<th>ID</th>
	                            	<th>Fund Name</th>
	                                <th>Number of Shares</th>
	                                <th>Actions</th>
	                            </tr>
							</thead>
							<tbody>
							<%
								Position [] positionList = new Position[0];
								ArrayList<String> fundNames = new ArrayList<String>();;
								if (request.getAttribute("positionList") != null){
								    //activeItems = (ItemType[])request.getAttribute("activeItems");
								    positionList = (Position[])request.getAttribute("positionList");
								    fundNames = (ArrayList<String>)request.getAttribute("fundNames");
								}
								
								Customer tempCustomer = null;
								
								for (int i = 0; i < positionList.length; i++) {
								    Position tempPosition = positionList[i];
								
							%>
								<tr>
									<td><%=tempPosition.getFundID() %></td>
									<td><%=fundNames.get(i) %></td>
	                            	<td style="text-align:right;padding-right:10px;"><%= Formatter.prepShareToView(tempPosition.getShares()) %></td>
	                                <td>
	                                	<a href="<%="#"+tempPosition.getFundID()%>" id="sell-funds"><img src="view/img/icons/money_delete.png" title="Sell Shares in this Fund" alt="Sell Shares"/></a>
	                                </td>
	                            </tr>
	                         <%
						
								}
							
							%>
							</tbody>
						</table>
					</div>
				</div>
	            
            </div>
            <jsp:include page="../common/sidebar.jsp" />
      </div>
        <jsp:include page="../common/footer.jsp" />
</div>
<div id="popup" >
<form id="form" action="#" method="post" class="sell-form">
	<div align="center">
		<input name="type" id="type" type="hidden" value="ajax"/>
		<input name="txtFundID" id="txtFundID" type="hidden" value=""/>
		<label for="txtShares" class="label-long">Number of Shares : </label>
		<input type="text" name="txtShares" size="20" value="${txtShares}" tabindex="2"/>
		<br />
		<input id="sell-fund" type="submit" name="Submit" value="Submit Sell Request" tabindex="3" /> 
		<input id="cancel" type="reset" tabindex="4" value="Cancel" />
	</div>
</form>
</div>
</body>
</html>
